// pages/ service/ detail.js
const app = getApp()
var postLogin = require("../../utils/wh.js");
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    modal:false,
    tranId: "",
    list: [],
    name:'',
    phone:'',
    remark:''
  },
  subscribe:function(){
    this.setData({
      modal:true
    })
  },
  close:function(){
    this.setData({
      modal: false
    })
  },

  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      tranId: options.id
    })
    wx.showLoading({
      title: '加载中•••',
      // mask: true
    })
    this.loop();
  },
  loop: function () {
    var that = this;
      var postUrl = '/api/company.transport/get_detail',
        postData = {
          tran_id: that.data.tranId
        };
      postLogin.Post(postUrl, postData, that.caseDetails);
  },
  caseDetails: function (res) { 
    console.log(res)
    let that = this;
    var list = res;
    wx.hideLoading();
    var article = res.content;
    WxParse.wxParse('article', 'html', article, this);
    that.setData({
      list: list,
    })
  },
  // 立即预约
  bindName: function (e) {
    this.setData({
      name: e.detail.value
    })
  },
  bindPhone: function (e) {
    this.setData({
      phone: e.detail.value
    })
  },
  bindRemark: function (e) {
    this.setData({
      remark: e.detail.value
    })
  },
  submitContent: function () {
    var name = this.data.name;
    var phone = this.data.phone;
    var remark = this.data.remark;
    if (!name || !phone) {
      wx.showToast({
        title: '请填写完整信息',
        icon: "none"
      })
      return false;
    }
    if (!(/^1[34578]\d{9}$/.test(phone))) {
      wx.showToast({
        title: '手机号格式错误',
        icon: "none"
      })
      return false;
    }
    var postUrl = '/api/company.transport/order',
      postData = {
        type:1,
        tran_id: this.data.tranId,
        name: this.data.name,
        mobile: this.data.phone,
        remark: this.data.remark,
      };
    postLogin.Post(postUrl, postData, this.submitsuccess);
  },
  submitsuccess: function () {
    wx.showToast({
      title: '提交成功',
      complete: function () {
        setTimeout(function () {
          wx.switchTab({
            url: '../service/service'
          })
        }, 2000);
      }
    })
    
    return;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})